<?php echo $this->renderElement('admin/menu'); ?>
<br />
<h2>Elements a valider</h2>
<div class="largebloc2">
<h3><?php echo __('no_linked_contracts'); ?></h3>
<table width="100%" border="0">
<?php
echo $html->tableHeaders(array('Id', __('ref_number', true), __('company', true), __('daily_rate', true), __('state', true), 'Actions'), 'class="details"');
	foreach($nolinkedcontracts as $contract):
		if ($contract['status'] == "open")
			$color = 'green'; // The contract is already validated, color is green.
		else
			$color = 'red'; // Red color, the contract needs validation.	
		echo "<tr>";
		echo "<td width='10%'>".$html->link("#".$contract['id'], '/contracts/view/'.$contract['id'])."</td>";
		echo "<td>".$html->link($contract['ref'], '/contracts/view/'.$contract['id'])."</td>";
		echo "<td>".$cf->getCompanyName($companies, $contract['company_id'])."</td>";
		echo "<td>".$contract['tjm']."</td>";
		echo '<td style="color:'.$color.'">'.$contract['status']."</td>";
		echo "<td width='20%'>".$html->link(__('validate', true), '/admin/contractValidate/'.$contract['id']).' | '.
					$html->link(__('edit', true), '/contracts/edit/'.$contract['id']).' | '.
					$html->link(__('view', true), '/contracts/view/'.$contract['id']).' | '.
					$html->link(__('delete', true), '/contracts/del/'.$contract['id'])."</td>";							
		echo "</tr>";
	endforeach;
?>
</table>
<br /><br />
<h3><?php echo __('projects_waiting_for_validation'); ?></h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php
echo $html->tableHeaders(array('Id', __('name', true), __('company', true), __('state', true), 'Actions'), 'class="details"');
foreach($projects as $key):
	// We get the contract linked to the project.
	$contract = $cf->getContract($contracts, $key['Project']['contract_id']);
	// If the contract is validated, the project become validatable.
	$action = '';
	if ($contract['status'] == "open"){
		$action = $html->link(__('validate', true), '/admin/projectValidate/'.$key['Project']['id']).' | ';
	}
	if ($key['Project']['status'] == "open")
		$color = 'green'; // The contract is already validated, color is green.
	else
		$color = 'red'; // Color red, the contract needs validation.
	echo "<tr>";
	echo "<td width='10%'>#".$key['Project']['id']."</td>";
	echo "<td width='25%'>".$key['Project']['name']."</td>";
	echo "<td width='25%'>".$cf->getCompanyName($companies, $key['Project']['company_id'])."</td>";
	echo "<td width='20%' style='color:".$color."'>".$key['Project']['status']."</td>";
	echo "<td width='20%'>".$action.
					$html->link(__('edit', true), '/projects/edit/'.$key['Project']['id']).' | '.
					$html->link(__('view', true), '/projects/view/'.$key['Project']['id'])."</td>";		
	echo "</tr>";
	echo "<tr><td></td>";
	if ($contract['status'] == "open"){
		$color = 'green'; // The contract is already validated, color is green.
		$actions = $html->link(__('edit', true), '/contracts/edit/'.$contract['id']).' | '
					.$html->link(__('view', true), '/contracts/view/'.$contract['id']);
	}
	else{
		$color = 'red'; // Color red, the contract needs validation.
		$actions = $html->link(__('validate', true), '/admin/contractValidate/'.$contract['id']).' | '.
					$html->link(__('edit', true), '/contracts/edit/'.$contract['id']).' | '.
					$html->link(__('view', true), '/contracts/view/'.$contract['id']);		
	}
	echo '<td colspan="4" style="padding-top:10px;padding-bottom:10px;"><table width="100%" border="0" cellspacing="0">';
	echo $html->tableHeaders(array('Id', __('ref_number', true), __('state', true), 'Actions'), 'class="tbl2head"');
			echo "<tr>";
			echo "<td width='10%'>".$html->link("#".$contract['id'], '/contracts/view/'.$contract['id'])."</td>";
			echo "<td width='40%'>".$html->link($contract['ref'], '/contracts/view/'.$contract['id'])."</td>";
			echo '<td width="20%" style="color:'.$color.'">'.$contract['status']."</td>";
			echo "<td width='20%'>".$actions."</td>";				
			echo "</tr>";
	echo "</table></td></tr>";
endforeach;
echo "</table>";
?>
<br /><br />
<h3><?php echo __('receiptbooks_waiting_for_validation'); ?></h3>
<table width="100%" border="0">
<?php
echo $html->tableHeaders(array('Id', __('name', true), __('company', true), __('available_amount', true), __('total_amount', true), __('close_date', true), __('status', true), 'Actions'), 'class="details"');
	foreach($receiptbooks as $rb):
		if ($rb['Receiptbook']['status'] == "open")
			$color = 'green'; // The contract is already validated, color is green.
		else
			$color = 'red'; // Red color, the contract needs validation.	
		echo "<tr>";
		echo "<td width='10%'>"."#".$rb['Receiptbook']['id']."</td>";
		echo "<td>".$rb['Receiptbook']['name']."</td>";
		echo "<td>".$cf->getCompanyName($companies, $rb['Receiptbook']['company_id'])."</td>";
		echo "<td>".$rb['Receiptbook']['free_amount']."</td>";
		echo "<td>".$rb['Receiptbook']['amount']."</td>";
		echo "<td>".$rb['Receiptbook']['close_date']."</td>";			
		echo '<td style="color:'.$color.'">'.$rb['Receiptbook']['status']."</td>";
		echo "<td width='15%'>".$html->link(__('validate', true), '/admin/receiptbookValidate/'.$rb['Receiptbook']['id'])." | ".
								$html->link(__('edit', true), '/receiptbooks/edit/'.$rb['Receiptbook']['id'])." | ".
								$html->link(__('delete', true), '/receiptbooks/del/'.$rb['Receiptbook']['id'])."</td>";
		echo "</tr>";
	endforeach;
?>
</table>
</div>